﻿using System;
using System.Data.Entity;
using AceSoft.RetailPlus.ContactModel;

namespace AceSoft.RetailPlus
{
    public class ContactDetailMock
    {
        public ContactDetailMock()
        {
            Contact _Contact = new Contact();

            var _ContactDetails = _Contact.ContactDetails;

            Console.WriteLine("Available contactdetails");
            foreach (ContactDetail _ContactDetail in _ContactDetails.Include("ContactNoes").Include("ContactAddresses"))
            {
                Console.WriteLine(" ID: {2}   _ContactDetail Name: {0}      EmailAddress: {1}", _ContactDetail.FirstName, _ContactDetail.EmailAddress, _ContactDetail.ID);
                foreach (ContactNo _ContactNo in _ContactDetail.ContactNoes)
                {
                    Console.WriteLine(" {0} : {1}", _ContactNo.ContactNoType, _ContactNo.PhoneNo);
                }
                foreach (ContactAddress _ContactAddress in _ContactDetail.ContactAddresses)
                {
                    Console.WriteLine(" AddressID: {2}   Address2: {0}      Address1: {1}", _ContactAddress.Address.Address2, _ContactAddress.Address.Address1, _ContactAddress.AddressID);
                }
            }

            Console.WriteLine("Deleting contactdetails");
            foreach (var _ContactDetail in _ContactDetails)
            {
                if (_ContactDetail.ID == 0)
                {
                    Console.WriteLine(" ContactDetail Name: {0} is a default and cannot be deleted.", _ContactDetail.FirstName);
                }
                else
                {
                    _ContactDetails.Remove(_ContactDetail);
                    Console.WriteLine(" ContactDetail Name: {0} deleted.", _ContactDetail.FirstName);
                }
            }
            _Contact.SaveChanges();

            Console.WriteLine("Adding contactdetails");
            for (int x = 0; x <= 10; x++)
            {
                _ContactDetails.Add(new ContactDetail { ID = x, Salutation = "Mr.", FirstName = "FName" + x, MiddleName = "M" + x, LastName = "LName" + x, EmailAddress = "EmailAddress" + x  + "@yahoo.com"});
                Console.WriteLine(" ContactDetail Name: {0} added.", "Name" + x);
                _Contact.SaveChanges();
            }

            Console.WriteLine("Relisting contactdetails");
            foreach (ContactDetail _ContactDetail in _ContactDetails.Include("ContactNoes").Include("ContactAddresses"))
            {
                Console.WriteLine(" ID: {2}   ContactDetail Name: {0}      EmailAddress: {1}", _ContactDetail.FirstName, _ContactDetail.EmailAddress, _ContactDetail.ID);
                foreach (ContactNo _ContactNo in _ContactDetail.ContactNoes)
                {
                    Console.WriteLine(" {0} : {1}", _ContactNo.ContactNoType, _ContactNo.PhoneNo);
                }
            }
        }
    }
}
